<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=
  , initial-scale=1.0"
    />
    <title>Document</title>
  </head>
  <body>
    <div id="test"></div>
    <div id="test1"></div>
    <div id="test2"></div>

    <script
      src="https://unpkg.com/react@16/umd/react.development.js"
      crossorigin
    ></script>
    <script
      src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"
      crossorigin
    ></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  </body>
  <script type="text/babel">
    //创建组件
    class Login extends React.Component {
      //初始化
      state = {
        username: "",
        password: "",
      };
      saveUsername = (event) => {
        this.setState({ username: event.target.value });
      };
      savePassword = (event) => {
        this.setState({ password: event.target.value });
      };
      handelSave = (event) => {
        event.preventDefault(); //阻止表单提交
        const { username, password } = this.state;
        alert(`你输入的用户名是${username}，输入的密码是${password}`);
      };
      render() {
        return (
          <form action="http://www.atguigu.com" onSubmit={this.handelSave}>
            用户名：
            <input
              onChange={this.saveUsername}
              type="text"
              name="username"
              id=""
            />
            密码：
            <input
              onBlur={this.savePassword}
              type="password"
              name="password"
              id=""
            />
            <button>登录</button>
          </form>
        );
      }
    }
    //渲染组件到页面
    ReactDOM.render(<Login />, document.getElementById("test"));
  </script>
</html>
